*** Data analysis - UK ***

use "data_UK"
*44 variables, 6577 observations

*** Data cleaning ***

**convert variables to numeric (from string) where possible
destring, replace

*identify the % of missing values
mdesc

**check unique identifier - OK
isid ResponseId
**check for duplicates - none
duplicates report

*Delete no consent/missing consent observations (96% remain)
tab consent, m sort
keep if consent=="I agree to participate"

*Delete wrong/missing answers newscomp1 (64% remain)
tab newscomp1, m sort
keep if newscomp1=="$1,500"

*Delete wrong/missing answers newscomp2 (81% remain)
tab newscomp2, m sort
keep if newscomp2=="Because he left his ID"

drop consent newscomp1 newscomp2
*41 variables, 3314 observations

*** Analysis ***

**Gender
tab gender, m sort

**Age 
sum age, d

**Educational level
tab education, m sort

**Employment status
tab dem_emp_current, m sort

**Received first dose COVID-19 vaccine 
tab receivedvaccine, m sort
replace receivedvaccine="Yes" if regexm(receivedvaccine,"Yes, I have received the first shot o")
tab receivedvaccine, m sort

**Parental status
gen agechildren_02=0
replace agechildren_02=1 if regexm(agechildren, "0-2")
gen agechildren_35=0
replace agechildren_35=1 if regexm(agechildren, "3-5")
gen agechildren_611=0
replace agechildren_611=1 if regexm(agechildren, "6-11")
gen agechildren_1216=0
replace agechildren_1216=1 if regexm(agechildren, "12-16")
gen agechildren_1718=0
replace agechildren_1718=1 if regexm(agechildren, "17-18")
gen agechildren_19=0
replace agechildren_19=1 if regexm(agechildren, "19")

label define children 0 "Non parent" 1 "Parent"
gen children_018=1 if agechildren_02==1 | agechildren_35==1 | agechildren_611==1 | agechildren_1216==1 | agechildren_1718==1 
replace children_018=0 if missing(children_018)
label var children_018 "Parent of children 0-18"
label val children_018 children

tab children_018, m
*1,212 parents of children 0-18

**Gen outcome variable vax_kid
gen vax_kid_02=Vax_friends_4 if children_018==0
replace vax_kid_02=Vax_child_02_4 if children_018==1 

gen vax_kid_35=Vax_friends_7 if children_018==0
replace vax_kid_35=Vax_child_35_4 if children_018==1

gen vax_kid_611=Vax_friends_8 if children_018==0
replace vax_kid_611=Vax_child_611_4 if children_018==1

gen vax_kid_1216=Vax_friends_9 if children_018==0
replace vax_kid_1216=Vax_child_1216_4 if children_018==1

gen vax_kid_1718=Vax_friends_10 if children_018==0
replace vax_kid_1718=Vax_child_1718_4 if children_018==1

label var vax_kid_02 "Probability to vaccinate kid 0-2 years old"
label var vax_kid_35 "Probability to vaccinate kid 3-5 years old"
label var vax_kid_611 "Probability to vaccinate kid 6-11 years old"
label var vax_kid_1216 "Probability to vaccinate kid 12-16 years old"
label var vax_kid_1718 "Probability to vaccinate kid 17-18 years old"

**Treatment
gen Treatchild=""
replace Treatchild="Risk" if treat_child_risk==1
replace Treatchild="Herd immunity" if treat_child_herd==1
replace Treatchild="Placebo" if treat_child_placebo==1
label define treatment 0 "Placebo" 1 "Herd immunity" 2 "Risk"
encode Treatchild, gen(Treatchild_enc) label(treatment)
label var Treatchild_enc "Treatment child"

gen treatment_herd=0 if Treatchild_enc==0
replace treatment_herd=1 if Treatchild_enc==1
label define herd 0 "Placebo" 1 "Herd immunity"
label val treatment_herd herd

gen treatment_risk=0 if Treatchild_enc==0
replace treatment_risk=1 if Treatchild_enc==2
label define risk 0 "Placebo" 1 "Risk"
label val treatment_risk risk

tab Treatchild, m

**Reasons hesitancy 
label var Novax_reason1_1 "Religious beliefs"
label var Novax_reason1_4 "Side effects"
label var Novax_reason1_5 "Vaccine will not work"
label var Novax_reason1_6 "Good hygiene is enough"
label var Novax_reason1_7 "It would be difficult to obtain the vaccine"
label var Novax_reason1_8 "I might accidentally miss the deadline to vaccinate"
label var Novax_reason1_9 "I'm bad with remembering things"
label var Novax_reason1_12 "I need more time to make a decision (after the summer)"
label var Novax_reason1_10 "Because most people will already be vaccinated"
label var Novax_reason1_11 "Other"

label var No_vax_friends_reas_1 "Religious beliefs"
label var No_vax_friends_reas_4 "Side effects"
label var No_vax_friends_reas_5 "Vaccine will not work"
label var No_vax_friends_reas_6 "Good hygiene is enough"
label var No_vax_friends_reas_7 "It would be difficult to obtain the vaccine"
label var No_vax_friends_reas_8 "I might accidentally miss the deadline to vaccinate"
label var No_vax_friends_reas_9 "I'm bad with remembering things"
label var No_vax_friends_reas_12 "I need more time to make a decision (after the summer)"
label var No_vax_friends_reas_10 "Because most people will already be vaccinated"
label var No_vax_friends_reas_11 "Other"

foreach var in Novax_reason1_1 Novax_reason1_4 Novax_reason1_5 Novax_reason1_6 Novax_reason1_7 Novax_reason1_8 Novax_reason1_9 Novax_reason1_12 Novax_reason1_10 Novax_reason1_11 {
	tab `var' if children_018==1, m
}

foreach var in No_vax_friends_reas_1 No_vax_friends_reas_4 No_vax_friends_reas_5 No_vax_friends_reas_6 No_vax_friends_reas_7 No_vax_friends_reas_8 No_vax_friends_reas_9 No_vax_friends_reas_12 No_vax_friends_reas_10 No_vax_friends_reas_11 {
	tab `var' if children_018==0, m
	}

**Trusted source of information
tab Trust_themost, m sort

gen trust_science=0
replace trust_science=1 if regexm(Trust_themost,"Public health experts") | regexm(Trust_themost,"Your GP") | regexm(Trust_themost, "Your local pharmacy") | regexm(Trust_themost, "Your local health care center")

tab trust_science if children_018==1, m sort
tab trust_science if children_018==0, m sort

***Reshape dataset
reshape long vax_kid_, i(ResponseId) j(AGE) string
drop if vax_kid_==.
label var vax_kid_ "Probability to vaccinate children"
*55 variables, 10792 observations

***Plots pdf and relative pdf
kdensity vax_kid_ , bwidth(3) nograph generate(x fx)

kdensity vax_kid_ if Treatchild_enc==0 & children_018==1, nograph bwidth(3) generate(p_fx0) at(x)
kdensity vax_kid_ if Treatchild_enc==1 & children_018==1, nograph bwidth(3) generate(p_fx1) at(x)
kdensity vax_kid_ if Treatchild_enc==2 & children_018==1, nograph bwidth(3) generate(p_fx2) at(x)

kdensity vax_kid_ if Treatchild_enc==0 & children_018==0, nograph bwidth(3) generate(np_fx0) at(x)
kdensity vax_kid_ if Treatchild_enc==1 & children_018==0, nograph bwidth(3) generate(np_fx1) at(x)
kdensity vax_kid_ if Treatchild_enc==2 & children_018==0, nograph bwidth(3) generate(np_fx2) at(x)

label var p_fx0 "Placebo"
label var p_fx1 "Herd immunity"
label var p_fx2 "Risk"

label var np_fx0 "Placebo"
label var np_fx1 "Herd immunity"
label var np_fx2 "Risk"

**Parents herd
line p_fx0 p_fx1 x, sort ytitle(Density) ylab(0(0.01)0.05, grid) graphregion(color(white)) xlabel(0(10)100, grid) lcolor(gs5 black) lpattern(dash)
graph save "pdf parents herd UK", replace
reldist pdf vax_kid_ if children_018==1, by(treatment_herd) vce(cluster ResponseId) bw(0.05)
reldist graph, ciopts(fcolor(%30) lcolor(%0)) xlabel(0(.1)1, grid labsize(vlarge)) xtitle(Proportion of placebo group, size(vlarge)) ylabel(0(.5)2, grid angle(0) labsize(vlarge)) ytitle(Relative density, size(vlarge)) olabel(0(10)100, labsize(vlarge)) graphregion(color(white)) lcolor(black) refline(lcolor(gs5) lpattern(dash))
graph save "rpdf parents herd UK", replace

**Parents risk
line p_fx0 p_fx2 x, sort ytitle(Density) ylab(0(0.01)0.05, grid) graphregion(color(white)) xlabel(0(10)100, grid) lcolor(gs5 black) lpattern(dash)
graph save "pdf parents risk UK", replace
reldist pdf vax_kid_ if children_018==1, by(treatment_risk) vce(cluster ResponseId) bw(0.05)
reldist graph, ciopts(fcolor(%30) lcolor(%0)) xlabel(0(.1)1, grid labsize(vlarge)) xtitle(Proportion of placebo group, size(vlarge)) ylabel(0(.5)2, grid angle(0) labsize(vlarge)) ytitle(Relative density, size(vlarge)) olabel(0(10)100, labsize(vlarge)) graphregion(color(white)) lcolor(black) refline(lcolor(gs5) lpattern(dash))
graph save "rpdf parents risk UK", replace

**Non parents herd
line np_fx0 np_fx1 x, sort ytitle(Density) xtitle(Probability to advise vaccination for children) ylab(0(0.01)0.05, grid) graphregion(color(white)) xlabel(0(10)100, grid) lcolor(gs5 black) lpattern(dash)
graph save "pdf non-parents herd UK", replace
reldist pdf vax_kid_ if children_018==0, by(treatment_herd) vce(cluster ResponseId) bw(0.05)
reldist graph, ciopts(fcolor(%30) lcolor(%0)) xlabel(0(.1)1, grid labsize(vlarge)) xtitle(Proportion of placebo group, size(vlarge)) ylabel(0(.5)2, grid angle(0) labsize(vlarge)) ytitle(Relative density, size(vlarge)) olabel(0(10)100, labsize(vlarge)) graphregion(color(white)) lcolor(black) refline(lcolor(gs5) lpattern(dash))
graph save "rpdf non-parents herd UK", replace

**Non parents risk  
line np_fx0 np_fx2 x, sort ytitle(Density) xtitle(Probability to advise vaccination for children) ylab(0(0.01)0.05, grid) graphregion(color(white)) xlabel(0(10)100, grid) lcolor(gs5 black) lpattern(dash)
graph save "pdf non-parents risk UK", replace
reldist pdf vax_kid_ if children_018==0, by(treatment_risk) vce(cluster ResponseId) bw(0.05)
reldist graph, ciopts(fcolor(%30) lcolor(%0)) xlabel(0(.1)1, grid labsize(vlarge)) xtitle(Proportion of placebo group, size(vlarge)) ylabel(0(.5)2, grid angle(0) labsize(vlarge)) ytitle(Relative density, size(vlarge)) olabel(0(10)100, labsize(vlarge)) graphregion(color(white)) lcolor(black) refline(lcolor(gs5) lpattern(dash))
graph save "rpdf non-parents risk UK", replace
